﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;

namespace Lingo
{
    class Round
    {
        public Word Word { get; set; }
        public int Guesses { get; set; }
        public int Number { get; set; }

        public Round()
        {
            this.Word = GenerateWord();
            this.Guesses = 0;
        }

        private Word GenerateWord()
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream stream = storage.OpenFile("words.txt", FileMode.Open, FileAccess.Read);

            List<string> words = new List<string>();
            using (StreamReader reader = new StreamReader(stream))
            {
                while (true)
                {
                    string word = reader.ReadLine();
                    if (word != null && !word.Equals(""))
                        words.Add(word);
                    else
                        break;
                }
            }
            Random r = new Random();
            int index = r.Next(0, words.Count - 1);

            return new Word(words[index]);
        }
    }
}
